using System;

namespace RockHopper.Common.Model
{
    public static class Vdot
    {
        public const double A1 = 0.000104;
        public const double A2 = 0.182258;
        public const double A3 = 4.6;
        public const double B1 = 0.298956;
        public const double B2 = 0.189438;
        public const double B3 = 0.8;
        public const double C1 = 0.193261;
        public const double C2 = 0.012778;
        public static double Minimum = 30;
        public static double Maximum = 85;

        public static double Resolve(double distance, int hours, int minutes, int seconds)
        {
            var timeInMinutes = new TimeSpan(hours, minutes, seconds).TotalMinutes;
            var velocity = distance / timeInMinutes;
            var oxygenCost = A1 * Math.Pow(velocity, 2) + A2 * velocity - A3;
            var percentMaxOxygenUptake = B3 + B1 * Math.Exp(-C1 * timeInMinutes) + B2 * Math.Exp(-C2 * timeInMinutes);
            var value = Math.Round(oxygenCost / percentMaxOxygenUptake, 1);//, MidpointRounding.AwayFromZero);

            if (value < Minimum) value = Minimum;
            if (value > Maximum) value= Maximum;

            return value;
        }
    }
}